package com.ffdms.mobileoffice;

import com.ffdms.service.StaffService;
import com.ffdms.vo.Staff;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class LoginActivity extends Activity implements OnClickListener {

	private Button mLoginBtn;
	private EditText mUserNameView;
	private EditText mPwdView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_login);
		init();
	}

	/**
	 * init widgets
	 */
	private void init() {
		mLoginBtn = (Button) findViewById(R.id.btnLogin);
		mUserNameView = (EditText) findViewById(R.id.txtUsername);
		mPwdView = (EditText) findViewById(R.id.txtpwd);
		mLoginBtn.setOnClickListener(this);
	}

	/**
	 * login function
	 */
	private void login() {
		StaffService ss = new StaffService(this, null);
		Staff staff = ss.Login(mUserNameView.getText().toString(), mPwdView
				.getText().toString());
		if (staff != null) {
			Intent main = new Intent(LoginActivity.this, MainActivity.class);
			startActivity(main);
			finish();
		} else {
			Toast.makeText(this, R.string.login_alert_loginfail_info,
					Toast.LENGTH_SHORT).show();
		}
	}

	private boolean checkNull() {
		boolean isNotNull = true;
		if (TextUtils.isEmpty(mUserNameView.getText().toString())) {
			isNotNull = false;
			Toast.makeText(this, R.string.login_alert_nullusername_info,
					Toast.LENGTH_SHORT).show();
		} else if (TextUtils.isEmpty(mPwdView.getText().toString())) {
			isNotNull = false;
			Toast.makeText(this, R.string.login_alert_nullpwd_info,
					Toast.LENGTH_SHORT).show();
		}
		return isNotNull;
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btnLogin:
//			if (checkNull()) {
//				login();
//			}
			Intent main = new Intent(LoginActivity.this, MainActivity.class);
			startActivity(main);
			finish();
			break;

		default:
			break;
		}
	}

}
